package com.nbjtjc.safe.api.sys;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.sys.SysDutyPublicMapper;
import com.nbjtjc.safe.model.sys.SysDutyPublic;
import com.nbjtjc.safe.service.sys.SysDutyPublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther guqianbin
 * @date 2018/7/23 14:58
 * 发布的值班
 **/
@RestController
@CrossOrigin("*")
@RequestMapping("/sysDutyPublic")
public class SysDutyPublicController {
    @Autowired
    private SysDutyPublicService sysDutyPublicService;

    @Autowired
    private SysDutyPublicMapper sysDutyPublicMapper;

    @PostMapping("/add")
    public Result add(SysDutyPublic sysDutyPublic){
        ValidatorUtils.validateEntity(sysDutyPublic);
        Result result=new Result();
        result.setData(sysDutyPublicService.add(sysDutyPublic));
        return result;
    }
    @PostMapping("/update")
    public Result update(SysDutyPublic sysDutyPublic){
        ValidatorUtils.validateEntity(sysDutyPublic,UpdateGroup.class);
        Result result=new Result();
        sysDutyPublicMapper.updateByPrimaryKeySelective(sysDutyPublic);
        result.setData(sysDutyPublic);
        return result;
    }
    @PostMapping("/find")
    public Result find(SysDutyPublic sysDutyPublic){
        Result result=new Result();
        result.setData(sysDutyPublicService.find(sysDutyPublic));
        return result;
    }

    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable("id") int sysDutyPublicId){
        Result result=new Result();
        sysDutyPublicMapper.deleteByPrimaryKey(sysDutyPublicId);
        return result;
    }
}
